package com.maxmlr.music.system.controller;

import com.maxmlr.music.common.bean.ResultBean;
import com.maxmlr.music.common.param.DictTypeParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;
import com.maxmlr.music.common.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.maxmlr.music.system.service.DictService;
import com.maxmlr.music.system.entity.Dict;
import io.swagger.annotations.*;

import java.io.Serializable;
import java.util.List;

/**
 * @author max
 * @version 1.0
 * @ClassName DictController
 * @Description 字典表 控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@RestController
@Api(value = "/system/dict" , tags = "Dict 控制器" )
@RequestMapping("/system/dict" )
public class DictController extends BaseController<DictService, Dict> {

    @Autowired
    public DictService service;

    /**
     * 保存
     *
     * @param dict
     * @return ResultBean<Boolean>
     */
    @PostMapping
    @RequiresPermissions("system:dict:add" )
    public ResultBean<Boolean> save(Dict dict) {
        return ResultBean.ok(service.save(dict));
    }

    /**
     * 修改
     *
     * @param dict
     * @return ResultBean<Boolean>
     */
    @PutMapping
    @RequiresPermissions("system:dict:edit" )
    public ResultBean<Boolean> update(Dict dict) {
        return ResultBean.ok(service.updateById(dict));
    }

    /**
     * 删除
     *
     * @param id
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/remove/{id}" )
    @RequiresPermissions("system:dict:remove" )
    public ResultBean<Boolean> remove(@PathVariable("id" ) Serializable id) {
        return ResultBean.ok(service.removeById(id));
    }

    /**
     * @Description 获取typeList
     * @author max
     * @since 2019-05-11
     */
    @GetMapping("/type")
    @ApiOperation(value = "/type", notes = "获取typeList")
    public ResultBean<List<DictTypeParam>> getTypes() {
        return ResultBean.ok(service.getTypes());
    }


}
